//
//  HMMainViewController.swift
//  WymanWeibo
//
//  Created by wyman on 16/4/8.
//  Copyright © 2016年 wyman. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
//        self.view.backgroundColor = UIColor.greenColor()
        
        let mainTabBar = HMMainTabBar()
        self .setValue(mainTabBar, forKey: "tabBar")
        
        mainTabBar.composeClousure = {
        
        let composeVc = HMComposeViewController()
        
        
        let nav = UINavigationController(rootViewController: composeVc)
            
        self.presentViewController(nav, animated: true, completion: nil)
            
            
        }
        
        self.setChidrenControllers()
    }

    
    //添加各个控制器
    func setChidrenControllers(){
        
        
      
        self.setupChildViewController(HMHomeViewController(), imageName: "tabbar_home", title: "首页")
        
       
        self.setupChildViewController(HMMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        
        
        self.setupChildViewController(HMDiscoverViewController(), imageName: "tabbar_discover", title: "发现")
      
        self.setupChildViewController(HMProfileViewController(), imageName: "tabbar_profile", title: "我")
    }
    
    //私有方法
   private func setupChildViewController(controller:UITableViewController,imageName:String,title:String){
    
        controller.tabBarItem.image = UIImage.init(named: imageName)
    
    //设置高亮图片(也可以在图片中设置属性)
    controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
    
        //设置标题颜色
    controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
    
    
    self.addChildViewController(UINavigationController.init(rootViewController: controller))
    controller.title = title
    }

}























